package xyz.eden.cloud.common.web.support.infrastructure.redis.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import xyz.eden.cloud.common.web.support.infrastructure.redis.IRedisResource;

import java.util.concurrent.TimeUnit;

/**
 * RedisResource
 * <so>https://juejin.cn/post/7175756564752990267</so>
 *
 * @author gavin
 * @version 1.0
 * @descriptor
 * @date 2023/5/1 10:55
 */
@Service
public class RedisResourceImpl implements IRedisResource {

    @Autowired
    private RedisTemplate<String, String> redisTemplate;


    @Override
    public String getVal(String key) {
        return redisTemplate.opsForValue().get(key);
    }

    @Override
    public void setVal(String key, String val, long timeout) {
        redisTemplate.opsForValue().set(key, val, timeout, TimeUnit.MINUTES);
    }

    @Override
    public void setVal(String key, String val) {
        redisTemplate.opsForValue().set(key, val);
    }
}
